//获取应用实例
const app = getApp()
const api = require('../../../api/index.js')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    plainData: {}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    app.message();

    if (options.formkey == 0){
      console.log('调用个人数据')
      this.getPlianData()
    } else if (options.formkey == 1) {
      console.log('调用亲子数据')
      this.getPlianDataTwo()
    }else{
      console.log('调用团队数据')
      this.getPlianDataThree()
    }

  },
 
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
   
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    App.zhuge.track('推荐表单页面', {
      '页面卸载': '页面卸载'
    });
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  },
  getPlianData: function(){
    console.log('我是个人提升来的数据')
    let Form = app.globalData.indexFormOne;
    let sex = 0;
    if (Form.sex.type == "猛男"){
      sex = 1;
    }else {
      sex = 2;
    }
    let data = {  // 个人提升上传数据
      region_id: Form.address.region_id,
      sex: sex,
      age: Form.age.age_part,
      aim: Form.purpose.aim_info,
      budget: Form.money.budget_part,
      social: Form.circle.social_name,
      mobile: Form.phone,
      plan_type: 1
    }

    api.parenting(data, (res) => {
      this.setData({
        plainData: res.data.result
      })
      console.log(res,res.data.result.name)
      App.zhuge.track('个人表单推荐的运动项目', {
        '个人表单推荐的运动项目': res.data.result.name
      });
    })
    console.log(data)
  },
  goVennue: function(e){
    let id = e.currentTarget.dataset.id;
    let name = e.currentTarget.dataset.name;
    app.globalData.vennueQuery = {
      id: id,
      name: name
    }
    console.log(id + name)
    wx.switchTab({
      url: `/pages/lookVennue/lookVennue/lookVennue`,
    })
  },

  getPlianDataTwo: function () {
    console.log('我是亲子教育来的数据')
    let Form = app.globalData.indexFormTwo;
    let sex = 0;
    if (Form.sex.baby_age == "男") {
      sex = 1;
    } else {
      sex = 2;
    }
    let data = {  // 亲子上传数据
      region_id: Form.address.region_id,
      baby_sex: sex,
      baby_age: Form.age.age_part,
      baby_aim: Form.purpose.hope_name,
      budget: Form.money.budget_part,
      social: Form.circle.social_name,
      mobile: Form.phone,
      plan_type: 2
    }

    api.parenting(data, (res) => {
      this.setData({
        plainData: res.data.result
      })
      console.log(res)
      App.zhuge.track('亲子推荐的运动项目', {
        '亲子推荐的运动项目': res.data.result.name
      });
    })
    console.log(data)
  },
  goVennue: function (e) {
    let id = e.currentTarget.dataset.id;
    let name = e.currentTarget.dataset.name;
    app.globalData.vennueQuery = {
      id: id,
      name: name
    }
    console.log(id + name)
    wx.switchTab({
      url: `/pages/lookVennue/lookVennue/lookVennue`,
    })
  },

  getPlianDataThree: function () {
    console.log('我是团队聚会来的数据')
    let Form = app.globalData.indexFormThree;
 
    let data = {  // 团队聚会上传数据
      'region_id': Form.address.region_id,
      'company_type': Form.sex.type_name,
      'ave_age': Form.age.age_part,
      'number': Form.purpose.number_part,
      'budget': Form.money.budget_part,
      'aim': Form.circle.aim_name,
      'mobile': Form.phone,
      'plan_type': 3
    }

    api.parenting(data, (res) => {
      this.setData({
        plainData: res.data.result
      })
      console.log(res)
      App.zhuge.track('团队推荐的运动项目', {
        '团队推荐的运动项目': res.data.result.name
      });
    })
    console.log(data)
  },
  goVennue: function (e) {
    let id = e.currentTarget.dataset.id;
    let name = e.currentTarget.dataset.name;
    app.globalData.vennueQuery = {
      id: id,
      name: name
    }
    console.log(id + name)
    wx.switchTab({
      url: `/pages/lookVennue/lookVennue/lookVennue`,
    })
  }

})